package com.transaction.stockseata.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author ausu
 * @version 1.0
 * @description: TODO
 * @date 2023/1/29 19:48
 */
@Component
public class RedisCache {

    @Autowired
    public RedisTemplate redisTemplate;

    public <T> void setCacheObject(String key, String value, Integer timeout, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
    }

    public <T> T getCacheObject(String key) {
        ValueOperations<String, T> valueOperations = redisTemplate.opsForValue();
        return valueOperations.get(key);
    }

}
